Original: 5/6/2020, Updated: 5/18/2020

Overview of assignment

Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities.

Your webpage must contain:
- the date that you created the document
- it must contain a plot created with Plotly

We would love to see you show off your creativity!

Overview of packages used in assigment:

  • Quantmod
  • Tidyverse
  • Plotly
  • Quantmod

Importing Data

You will need to first pick a time range that you want to look at:

start <- as.Date("2020-01-01")
end <- as.Date("2020-05-18")

You will then need to pick your stocks of interest. In this case, we are looking at DFS.

getSymbols("DFS", src = "yahoo", from = start, to = end)

Stock Dataframe

The getSymbols() function imports your stock data as a timeseries of class "xts" or "zoo", so you need to convert this to a dataframe. Be sure to keep index (date).

          date DFS.Open DFS.High DFS.Low DFS.Close DFS.Volume DFS.Adjusted
  1 2020-01-02    85.11    85.31   84.47     85.30    1559200     84.80190
  2 2020-01-03    84.01    84.43   83.35     83.88    1068300     83.39019
  3 2020-01-06    83.01    83.38   81.67     82.40    2278300     81.91883
  4 2020-01-07    81.96    82.39   81.39     81.49    1926300     81.01414
  5 2020-01-08    81.67    83.06   81.35     82.37    2092300     81.88901
  6 2020-01-09    82.94    83.49   82.92     83.43    1580100     82.94282

Importing major world events

In order to compare DFS with major world events, we need to import world event data. Data was taken from: https://www.nytimes.com/article/coronavirus-timeline.html

          date                                descr
  1 2020-01-02     Unknown pneumonia cases in China
  2 2020-01-11                 First death in China
  3 2020-01-13 First case recorded outside of China
  4 2020-01-20            First case reported in US
  5 2020-01-30 WHO declared global health emergency
  6 2020-01-31       US restricts travel from China

Make a plot using ggplot

Make an interactive plot

We can also create an interactive plot (but unfortunately we lose the world event labels). If you hover, you can see open (green) and close (red) prices for each day.